package com.zhou.common.operator.log.core.holder;

import com.google.common.base.Optional;
import com.google.common.collect.Maps;

import java.util.Map;

/**
 * 操作说明附加的参数列表（用来指定spel中的额外参数）
 * 注意不能命名重复，（切面方法的入参，res和exception）
 *
 * @author xianfeng
 * @date 2023/8/25 16:08
 */
public class OperatingInstructionAdditionalParamHolder {

    private static ThreadLocal<Map<String, Object>> userDetailThreadLocal = new ThreadLocal<>();


    public static void addParam(String key, Object value) {
        Map<String, Object> map = userDetailThreadLocal.get();
        if (map == null) {
            map = Maps.newHashMap();
            userDetailThreadLocal.set(map);
        }
        map.put(key, value);
    }

    public static Optional<Map<String, Object>> getParams() {
        Map<String, Object> map = userDetailThreadLocal.get();
        return Optional.fromNullable(map);
    }

    public static void clear() {
        userDetailThreadLocal.remove();
    }
}
